//
//  BaseMessageTableViewCell.m
//  TQY
//
//  Created by 甘世清 on 2024/10/18.
//

#import "BaseMessageTableViewCell.h"
@interface BaseMessageTableViewCell ()
@property (nonatomic, strong) UILabel *nameLab;//名字

@property (nonatomic, strong) UILabel *timelab;//时间

@end
@implementation BaseMessageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle: style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
       
        [self.contentView addSubview:self.headerView];
        [self.contentView addSubview:self.timelab];
        [self.timelab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.height.mas_equalTo(20);
            make.top.equalTo(self.contentView).offset(8);
        }];
//        [self.contentView addSubview:self.nameLab];
//        [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerY.equalTo(self.headerView);
//            make.right.equalTo(self.headerView.mas_right);
//        }];
       
    }
    return self;
}
/**
 填充基类数据

 @param model 聊天模型数据
 */
- (void)setModel:(IMMessageModel *)model{
    _model = model;
//    self.nameLab.text = self.model.messageId;
    //发送者是否是自己
    if (model.isSend) {
        [self.headerView.headerImage sd_setImageWithURL:SQURLImage([UserModel share].portrait) placeholderImage:SQGetImage(@"1")];
    } else {
        [self.headerView.headerImage sd_setImageWithURL:SQURLImage(model.toUserPortrait) placeholderImage:SQGetImage(@"1")];
    }
    _timelab.text = model.showTime;
    _timelab.hidden = !model.isShowTime;
    self.headerView.frame = model.isSend?CGRectMake(SCREEN_WIDETH-60, model.isShowTime?30:5,50, 50):CGRectMake(10, model.isShowTime?35:5, 50, 50);
}
-(void)SQ_buttonClick{
    if (self.SQ_menuTouchActionBlock) {
        self.SQ_menuTouchActionBlock(@"点击头像");
    }
}

- (UILabel *)timelab{
    if (!_timelab) {
        _timelab = [[UILabel alloc]init];
        _timelab.textColor = SQColor999999;
        _timelab.font = FONT_REGULAR(12);
        _timelab.textAlignment = NSTextAlignmentCenter;
    }
    return _timelab;
}
- (UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc]init];
        _nameLab.textColor = SQColor666666;
        _nameLab.font = FONT_REGULAR(14);
    }
    return _nameLab;
}
- (HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc]init];
        _headerView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
        _headerView.clipsToBounds = YES;
        _headerView.layer.cornerRadius = 25;
        _headerView.layer.masksToBounds = YES;
        [_headerView.btn addTarget:self action:@selector(SQ_buttonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _headerView;
}
- (UIView *)hudView{
    if (!_hudView) {
        _hudView = [[UIView alloc]init];
        _hudView.backgroundColor = UIColor.clearColor;
    }
    return _hudView;
}
- (UIActivityIndicatorView *)hud{
    if (!_hud) {
        _hud = [[UIActivityIndicatorView  alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];
        _hud.center = CGPointMake(10, 10);
        _hud.color = SQColor999999;
    }
    return _hud;
}
- (SQCustomButton *)reloadBtn{
    if (!_reloadBtn) {
        _reloadBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(24, 24) midmargin:0];
        _reloadBtn.image = SQGetImage(@"fasongshibai");
    }
    return _reloadBtn;
}
@end
